<?php

namespace App\Observers;

use App\Models\Tags;
use App\server\EsServer;
use App\server\RedisServer;

class TagsObserver
{
    /**
     * Handle the Tags "created" event.
     *
     * @param  \App\Models\Tags  $tags
     * @return void
     */
    public function created(Tags $tags)
    {
        $Es=new EsServer();
        $Es->EsAdd('tags',$tags->toArray());
        $redis=RedisServer::createRedisObject();
        $redis->select(14);
        $data=$tags->toArray();
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the Tags "updated" event.
     *
     * @param  \App\Models\Tags  $tags
     * @return void
     */
    public function updated(Tags $tags)
    {
        $data= $tags->toArray();
        $redis=RedisServer::createRedisObject();
        $redis->select(14);
        foreach ($data as $key => $value){
            $redis->hset($data['id'],$key,$value);
        }
    }

    /**
     * Handle the Tags "deleted" event.
     *
     * @param  \App\Models\Tags  $tags
     * @return void
     */
    public function deleted(Tags $tags)
    {
        //
    }

    /**
     * Handle the Tags "restored" event.
     *
     * @param  \App\Models\Tags  $tags
     * @return void
     */
    public function restored(Tags $tags)
    {
        //
    }

    /**
     * Handle the Tags "force deleted" event.
     *
     * @param  \App\Models\Tags  $tags
     * @return void
     */
    public function forceDeleted(Tags $tags)
    {
        //
    }
}
